<template>
	<gui-page ref="guiPage" :customHeader="true">
		<!-- 导航 -->
		<template v-slot:gHeader>
			<nav-bar-custom left-icon="left"  :title="$t('打包标记NG')"				
				@clickLeftBack="clickLeftBack" scanType="0"></nav-bar-custom>
		</template>

		<template v-slot:gBody>
			<view class="barcodeSplitting">
				<!-- 扫描条码部分 -->
				<view class="gui-bg-white gui-dark-bg-level-3 gui-padding-x distributed-head">
					<view class="custom-card-title">
						<text class="title-line"></text>
						{{ $t('Common.scanningInfo') }}
					</view>
					<view class="gui-form-item gui-border-b" style="padding: 20rpx 0;">
						<text class="item-info-title" style="padding-right: 40rpx;">
							<text class="required-color">*</text>
							{{ $t('distributedEnter.barcodeScan') }}
						</text>
						<uni-easyinput class="uni-mt-5" suffixIcon="scan" v-model="data.barCodes" type="search"
							:placeholder="$t('Common.scanningBarCode')" @confirm="confirm" @iconClick="iconClick">
						</uni-easyinput>
					</view>
				</view>

				
				<!-- 底部确定按钮 -->
				<view class="page-bottom-box bottom-postion">
					<view class="page-bottomBtn bottomBtn-bgcolor-green"  @click="submitConfirmFn">{{ $t('calendar.submit') }}</view>
					</view>
			</view>
		</template>
	</gui-page>
</template>

<script setup>
//引入文件
import { navigate, navigateBack } from '@/utils/routerSkip.js';
import { ref, reactive, onMounted, computed, watch, toRaw } from "vue";
import { getHgBarCodeResponse, setDRNg } from '@/api/api.js'
import pdaScan from '@/hooks/pdaScan.js'
import storageBin from '@/components/storageBin.vue'
import comboGrid from '@/components/comboGrid.vue'
import { onBackPress } from '@dcloudio/uni-app';
import { useStore } from "vuex";
import { basPdaOperationLogFn } from '@/utils/index.js';
import superweiCombox from '@/components/superweiCombox';
import { USERINFO, OPERATION_COMMIT, OPERATION_LOOK, OPERATION_SCAN } from '@/constant/index.js'

//JS国际化引入
import { useI18n } from 'vue-i18n';
//注册组件
components: { comboGrid }
const { t } = useI18n();
let store = useStore();
const { scan } = pdaScan();



const data = reactive({
	barCodes: '',  
})


onMounted(() => {
	uni.$on('scancodedate', (scan) => {
		data.barCodes=scan.code
	})
})





// 扫描条码  监听用户使用相机
const iconClick = async (type) => {
	if (type === 'suffix') {
		let code = await scan();
		data.barCodes=code
	}
}


// 提交弹框确定
const submitConfirmFn = () => {
	
	   const parmes={
		   barCode:data.barCodes,		   
	   }
	   
	   
	   if(data.barCodes==''){
		   uni.showToast({
		   	    title:'条码不能为空!',
				icon:'error'
		   })
		   return
	   }
	
		setDRNg(parmes).then(res => {
			try {
				let inputParameter = '无'
				let returnParameter = JSON.stringify(data.barcodeList)
				let operationPicture = 'NG标记'
				let callInterface = '无'
				let opertionParmes = {
					inputParameter,
					returnParameter,
					operationPicture,
					callInterface,
					responseCode: res.code,//返回状态
					errorMessage: res.message,//错误信息
					isPass: res.code == 200 ? 'Y' : 'N',//是否成功 Y N
					operationType: OPERATION_COMMIT,
					module: 'WMS',
					source: "PDA",
				}
				basPdaOperationLogFn(opertionParmes)
			} catch (error) {
				// console.log(error)
			}
			// 接口调用成功执行
			if (res.code == 200) {
				
			   
				uni.showToast({ title: t('smashRemoval.submitSuccessfully'), icon: "none" });

			}
			else {
				uni.showModal({
					content: res.message,
					showCancel: false,
					confirmText: 'close'
				})

			}
		})
}



//导航栏左侧返回
const clickLeftBack = () => {
	navBackCheck()
}
const navBackCheck = () => {
	uni.navigateBack({
		delta: 1
	});
}
//点击物理按键的返回
onBackPress((options) => {
	if (options.from == 'backbutton') {
		uni.navigateBack({
			delta: 1
		});
		return true;
	}
})

</script>

<style lang="scss" scoped>
.barcodeSplitting {
	display: flex;
	flex-direction: column;
	height: calc(100vh - 88rpx);
	// height: 100vh;
}

.distributed-head {
	border-bottom-left-radius: 16rpx;
	border-bottom-right-radius: 16rpx;
}

.scroll {
	flex: 1;
	height: 2rpx;
}
</style>
